<template>
  <div class="sidebar">
    <div
      class="sidebar-title"
      style="display: flex;align-items: center;justify-content: center;"
    >
      <!-- <img src="../../assets/logo.png" style="width: 95%;" /> -->
      济特小程序管理平台
    </div>
    <div class="sidebar-box">
      <el-menu
        class="el-menu-vertical-demo"
        :collapse="false"
        :default-active="activeMenu"
        background-color="transparent"
        :text-color="variables.menuText"
        :unique-opened="false"
        :active-text-color="variables.menuActiveText"
        :collapse-transition="false"
        mode="vertical"
      >
        <SidebarItem
          v-for="route in navList"
          :key="route.menuId"
          :item="route"
          :base-path="route.url"
        >
        </SidebarItem>
      </el-menu>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import SidebarItem from "./SidebarItem";

export default {
  components: {
    SidebarItem,
  },
  computed: {
    ...mapGetters(["permission_routes"]),
    activeMenu() {
      const route = this.$route;
      const { meta, path } = route;
      // 默认激活项
      if (meta.activeMenu) {
        return meta.activeMenu;
      }
      // let menuId = sessionStorage.getItem('menuId');
      // console.log(path)
      let a = path.slice(1);
      // console.log(a)
      //必须要和item中的index的值一样时，才能默认选中
      return a;
    },
    variables() {
      return {
        menuText: "#ffffff", // "#bfcbd9"
        menuActiveText: "#ffffff",
        menuBg: "#001529",
      };
    },
  },
  data() {
    return {
      navList: [
        {
          menuId: 57,
          parentId: 0,
          parentName: "",
          name: "首页",
          url: "index",
          perms: "",
          type: 1,
          icon: "el-icon-s-home",
          orderNum: 0,
          open: "",
          list: "",
        },
        {
          menuId: 1,
          parentId: 0,
          parentName: "",
          name: "系统管理",
          url: "goods",
          perms: "goods",
          type: 0,
          icon: "el-icon-menu",
          orderNum: 4,
          open: "",
          list: [
            {
              menuId: 2,
              parentId: 1,
              parentName: "",
              name: "用户管理",
              url: "goods/user",
              perms: "",
              type: 1,
              icon: "el-icon-s-custom",
              orderNum: 1,
              open: "",
              list: "",
            },
            {
              menuId: 3,
              parentId: 1,
              parentName: "",
              name: "角色管理",
              url: "goods/role",
              perms: "",
              type: 1,
              icon: "el-icon-s-check",
              orderNum: 2,
              open: "",
              list: "",
            },
            {
              menuId: 4,
              parentId: 1,
              parentName: "",
              name: "菜单管理",
              url: "goods/menu",
              perms: "",
              type: 1,
              icon: "el-icon-s-check",
              orderNum: 3,
              open: "",
              list: "",
            },
          ],
        },
      ],
    };
  },
  created() {
    this.getNav();
  },
  mounted() {
    // console.log(this.permission_routes,12)
  },
  methods: {
    getNav() {
      // sessionStorage.setItem('menuList', JSON.stringify(this.navList));
      // sessionStorage.setItem('oneid', this.navList[0].menuId);
      this.Sevice({
        url: "sys/menu/nav",
        method: "get",
      })
        .then((res) => {
          if (res && res.code == 200) {
            sessionStorage.setItem("menuArr", JSON.stringify(res.menuList));
            sessionStorage.setItem("menuList", JSON.stringify(res.permissions));
            if (res.menuList.length) {
              sessionStorage.setItem("oneid", res.menuList[0].menuId);
            } else {
              sessionStorage.setItem("oneid", "");
            }
            // console.log(res.menuList)
            this.navList = res.menuList;
          } else {
            this.navList = [];
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style scoped>
.sidebar {
  width: 100%;
  height: 100%;
}

.sidebar-title {
  width: 100%;
  height: 50px;
  border-bottom: 1px solid #dcdfe6;
  color: #ffffff;
  box-sizing: border-box;
  text-align: center;
  line-height: 50px;
  font-size: 16px;
}

.sidebar-box {
  width: 100%;
  height: calc(100% - 64px);
  overflow-x: hidden;
  overflow-y: auto;
  -ms-overflow-style: none;
  overflow: "-moz-scrollbars-none";
  scrollbar-width: none;
  /*  火狐   */
}

.sidebar-box::-webkit-scrollbar {
  display: none;
  /*  Chrome  */
  width: 0 !important;
  /*  Chrome  */
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>
